package com.example;

/**
 * @Author loubobooo
 * @Description #82. 删除排序链表中的重复元素 II
 * @Date 2022/3/3
 */
public class RemoveDuplicatesFromSortedListIi {

    class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    /**
     * 方法描述:给定一个已排序的链表的头 head ， 删除原始链表中所有重复数字的节点，只留下不同的数字 。返回 已排序的链表 。
     *
     * @param: [head]
     * @return: com.example.RemoveDuplicatesFromSortedListIi.ListNode
     * @author: loubobooo
     * @date: 2022/3/3
     */
    public ListNode deleteDuplicates(ListNode head) {
        if(head == null){
            return head;
        }
        ListNode cur = head;
        while(cur.next != null){
            ListNode next = cur.next;
            if(cur.val == next.val){
                cur.next = next.next;
            }else{
                cur = cur.next;
            }
        }
        return head;
    }
}